var fn_index = async (ctx, next) => {

    // global.sequelize.query('SELECT * FROM user', { type: sequelize.QueryTypes.SELECT })
    // .then(function (results) {
    //     // SELECT query - use then
    //     console.log(results);
    // });

    let title = ctx.session.user ? `Hello, ${ctx.session.user.username}` : 'Welcome'
    ctx.render('login.html', {
        name: 'Robot',
        age: 15
    });
};

var fn_signin = async (ctx, next) => {
    var email = ctx.request.body.email || '';
    var password = ctx.request.body.password || '';
    console.log(`signin with name: ${email}, password: ${password}`);
    if (email === 'admin@example.com' && password === '123456') {
        ctx.session.user = {
            "username": email,
            "password": password
        };
        ctx.render('signin-ok.html', {
            title: 'Sign In OK',
            name: 'Mr Node'
        });
    } else {
        ctx.render('signin-failed.html', {
            title: 'Sign In Failed'
        });
    }
};

module.exports = {
    'GET /': fn_index,
    'POST /signin': fn_signin
};